package edu.cibertec.sicsolutions.util;

import java.io.IOException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class SecurityUtil {
	
	public static String encode64(String st) throws Exception {
		java.security.MessageDigest md = java.security.MessageDigest
				.getInstance("MD5");
		byte[] bytes = md.digest(st.trim().getBytes());
		return encode64(bytes).trim();
	}

	public static String encode64(byte st[]) throws Exception {
		return (new BASE64Encoder()).encodeBuffer(st);
	}

	public static byte[] decode64(String st) throws Exception {
		return (new BASE64Decoder()).decodeBuffer(st);
	}

	public static String decode(String s) throws IllegalArgumentException,IOException {
		byte[] sBytes = (new BASE64Decoder()).decodeBuffer(s);
		s = new String(sBytes);
		return s;
	}
}
